package com.bestom.bluetoothlock.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.bestom.bluetoothlock.R;
import com.bestom.bluetoothlock.bluetooth.BleServiceManage;
import com.bestom.bluetoothlock.bluetooth.BraceletInstructions;
import com.bestom.bluetoothlock.entity.DeviceInfo;
import com.bestom.bluetoothlock.entity.ReceiveInfo;
import com.bestom.bluetoothlock.util.Constants;
import com.bestom.bluetoothlock.util.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FingerprintSettingActivity extends BaseActivity {
    private static final int HANDLER_MESS_RECEIVE = 0;
    /* access modifiers changed from: private */
    public BleServiceManage bleManage;
    /* access modifiers changed from: private */
    public DeviceInfo deviceInfo;
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        public void handleMessage(Message message) {
            super.handleMessage(message);
            if (message.what == 0) {
                ReceiveInfo receiveInfo = (ReceiveInfo) message.obj;
                String cmd = receiveInfo.getCmd();
                String result = receiveInfo.getResult();
                if (cmd.equals(BraceletInstructions.INSTRUCTIONS_RESET_FINGER)) {
                    if (result.equals("00")) {
                        FingerprintSettingActivity.this.tv_number.setText("0");
                        ToastUtil.toast(FingerprintSettingActivity.this.getString(R.string.clear_fingerprint_success));
                        return;
                    }
                    ToastUtil.toast(FingerprintSettingActivity.this.getString(R.string.clear_fingerprint_fail));
                } else if (cmd.equals(BraceletInstructions.INSTRUCTIONS_FINGER_NUMBER) && result.equals("00")) {
                    FingerprintSettingActivity.this.tv_number.setText(String.valueOf(Integer.valueOf(receiveInfo.getValue(), 16)));
                }
            }
        }
    };
    @SuppressLint("HandlerLeak")
    private Handler handlerListen = new Handler() {
        public void handleMessage(Message message) {
            super.handleMessage(message);
            int i = message.what;
            if (i != 1) {
                if (i == 3) {
                    ReceiveInfo receiveInfo = (ReceiveInfo) message.obj;
                    String cmd = receiveInfo.getCmd();
                    String result = receiveInfo.getResult();
                    if (cmd.equals(BraceletInstructions.INSTRUCTIONS_RESET_FINGER)) {
                        if (result.equals("00")) {
                            FingerprintSettingActivity.this.tv_number.setText("0");
                            ToastUtil.toast(FingerprintSettingActivity.this.getString(R.string.clear_fingerprint_success));
                            return;
                        }
                        ToastUtil.toast(FingerprintSettingActivity.this.getString(R.string.clear_fingerprint_fail));
                    } else if (cmd.equals(BraceletInstructions.INSTRUCTIONS_FINGER_NUMBER) && result.equals("00")) {
                        FingerprintSettingActivity.this.tv_number.setText(String.valueOf(Integer.valueOf(receiveInfo.getValue(), 16)));
                    }
                }
            } else if (!((Boolean) message.obj).booleanValue()) {
                ToastUtil.toast(FingerprintSettingActivity.this.getString(R.string.device_disconnect));
                FingerprintSettingActivity.this.bleManage.connect(FingerprintSettingActivity.this.deviceInfo);
                FingerprintSettingActivity.this.finish();
            }
        }
    };
    @BindView(R.id.iv_left)
    ImageView iv_left;
    @BindView(R.id.tv_number)
    TextView tv_number;
    @BindView(R.id.tv_register_fingerprint)
    TextView tv_register_fingerprint;
    @BindView(R.id.tv_fingerprint_manage)
    TextView tv_reset_fingerprint;
    @BindView(R.id.tv_title)
    TextView tv_title;

    /* access modifiers changed from: protected */
    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_fingerprint_setting);
        ButterKnife.bind((Activity) this);
        this.deviceInfo = (DeviceInfo) getIntent().getSerializableExtra(Constants.KEY_VALUE);
        initView();
    }

    private void initView() {
        this.tv_title.setText(getString(R.string.fingerprint_setting));
        this.iv_left.setVisibility(0);
        this.bleManage = BleServiceManage.getInstance(this);
        this.bleManage.setHandlerListener(this.handlerListen);
    }

    /* access modifiers changed from: private */
    public void gainFingerNmu() {
        Log.d("agui", "get finger print count");
        this.bleManage.sendData(BraceletInstructions.getFingerNumberInstructions());
    }

    /* access modifiers changed from: package-private */
    @OnClick({R.id.tv_fingerprint_manage, R.id.tv_register_fingerprint, R.id.iv_left})
    public void onClickView(View view) {
        int id = view.getId();
        if (id == R.id.iv_left) {
            finish();
        } else if (id == R.id.tv_fingerprint_manage) {
            Intent intent = new Intent(this, FingerprintManageActivity.class);
            intent.putExtra(Constants.KEY_VALUE, this.deviceInfo);
            startActivity(intent);
        } else if (id == R.id.tv_register_fingerprint) {
            Intent intent2 = new Intent(this, RegisterFingerprintActivity.class);
            intent2.putExtra(Constants.KEY_VALUE, this.deviceInfo);
            startActivity(intent2);
        }
    }

    /* access modifiers changed from: protected */
    public void onResume() {
        BleServiceManage bleServiceManage;
        super.onResume();
        Handler handler2 = this.handlerListen;
        if (!(handler2 == null || (bleServiceManage = this.bleManage) == null)) {
            bleServiceManage.setHandlerListener(handler2);
        }
        this.handler.postDelayed(new Runnable() {
            public void run() {
                FingerprintSettingActivity.this.gainFingerNmu();
            }
        }, 500);
    }
}
